package com.qlk.vorder.manager.impl;

import java.util.List;

import com.qlk.common.manager.BaseManager;
import com.qlk.common.utils.page.PageUtil;
import com.qlk.vorder.domain.SerialLog;
import com.qlk.vorder.domain.query.SerialLogQuery;
import com.qlk.vorder.dao.SerialLogDao;
import com.qlk.vorder.manager.SerialLogManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * SerialLogManager接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-7-28 14:14:00
 * 
 */
@Component
public class SerialLogManagerImpl extends BaseManager implements SerialLogManager {

	@Autowired
	private SerialLogDao serialLogDao;

	/**
	 * {@inheritDoc}
	 */
	public boolean insert(final List<SerialLog> serialLogList) {
		boolean resultFlag = false;
		if (null != serialLogList && serialLogList.size() > 0) {
			for (SerialLog serialLog : serialLogList) {
				resultFlag = serialLogDao.insert(serialLog);
				if (!resultFlag) {
					throw new RuntimeException("批量新增表信息异常");
				}
			}
		}

		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean insert(SerialLog serialLog) {
		return serialLogDao.insert(serialLog);
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean update(final SerialLog serialLog) {
		return serialLogDao.update(serialLog);
	}

	/**
	 * {@inheritDoc}
	 */
	public List<SerialLog> querySerialLogList(SerialLogQuery queryBean) {
		return serialLogDao.querySerialLogList(queryBean);
	}

	/**
	 * {@inheritDoc}
	 */
	public List<SerialLog> querySerialLogListWithPage(SerialLogQuery queryBean, PageUtil pageUtil) {
		if (null == queryBean) {
			queryBean = new SerialLogQuery();
		}

		// 查询总数
		int totalItem = querySerialLogCount(queryBean);

		if (pageUtil == null) {
			pageUtil = new PageUtil();
		}
		pageUtil.setTotalRow(totalItem);
		pageUtil.init();

		if (totalItem > 0) {
			queryBean.setPageIndex(pageUtil.getCurPage());
			queryBean.setPageSize(pageUtil.getPageSize());
			// 调用Dao翻页方法
			return serialLogDao.querySerialLogListWithPage(queryBean);
		}
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	public int querySerialLogCount(SerialLogQuery queryBean) {
		return serialLogDao.querySerialLogCount(queryBean);
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean delete(SerialLog serialLog) {
		return serialLogDao.delete(serialLog);
	}

	/**
	 * {@inheritDoc}
	 */
	public SerialLog getSerialLogById(Long id) {
		return serialLogDao.getSerialLogById(id);
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean delete(final SerialLog[] serialLogs) {
		boolean resultFlag = false;
		if (null != serialLogs && serialLogs.length > 0) {
			for (int i = 0; i < serialLogs.length; i++) {
				resultFlag = delete(serialLogs[i]);
				if (!resultFlag) {
					throw new RuntimeException("批量删除表信息异常!");
				}
			}
		}

		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean exist(SerialLog serialLog) {
		return serialLogDao.exist(serialLog);
	}
}
